<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_bdd.php';

$message_action = isset($_GET["message_action"]) ? unserialize($_GET["message_action"]) : "";
$order = isset($_GET['ordre']) ? "ORDER BY raison_sociale ".$_GET['ordre'] : "";
$sql = "SELECT * FROM entreprises ".$order;
$envoi_requete = mysqli_query($connexion_serveur, $sql);

$nbre_total = mysqli_num_rows($envoi_requete);

?>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Liste Entreprises</title>
        <?php require_once "../inc/css_bootstrap.php" ?>
        <style>
            .table {
                width: 500px;
                
            }
            
            th {
                width: 35%;
                text-align: right;
            }
        </style>
    </head>
    <body>
        <?php require_once '../inc/menu_principal.php'; ?>
        <h1>LISTE DES ENTREPRISES</h1>
        <div style="margin:15px;">Nombre d'entreprises affichées : <?php echo $nbre_total; ?></div>
        
        <?php
        while($resultat= mysqli_fetch_array($envoi_requete)){
            ?>
        
        <div>
            <table class="table table-bordered">
                <tr class="active">
                    <th>N°</th>
                    <td>  <?php echo $resultats["id"]?>
                        <div class="btn-group" style="float: right;">
                            <button type="button" class="btn btn-warning btn-xs" data-toggle="dropdown">
                                Action
                                <button type="button" class="btn btn-warning btn-xs dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                    <span class="sr-only">Toggle Dropdown</span>
                                </button>
                            </button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="modifier_entreprises.php?id=<?php echo $resultats["id"]; ?>">Modifier</a></li>
                                <li><a href="supprimer_entreprises.php?action=1&id=<?php echo $resultats["id"]; ?>">Supprimer</a></li>
                            </ul>
                        </div>
                    </td>
                    </td>
                </tr>
                <tr>
                    <th>Raison sociale</th>
                    <td><a href="../contacts/liste_contacts.php?id=<?php echo $resultat["id"]; ?>"><?php echo $resultat["raison_sociale"]; ?></a></td>
                </tr>           
                <tr>
                    <th>Adresse</th>
                    <td>  <?php echo $resultat['adresse']; ?></td>
                </tr>
                <tr>
                    <th>Telephone</th>
                    <td>  <?php echo $resultat['telephone']?></td>
                </tr>
                <tr>
                    <th>Fax</th>
                    <td>  <?php echo $resultat['fax']?></td>
                </tr>
                <tr>
                    <th>Email</th>
                    <td>  <?php echo $resultat['email']?></td>
                </tr>
                <tr>
                    <th>Observations</th>
                    <td>  <?php echo $resultat['observations']?></td>
                </tr>
                
            </table>
        </div>

        <?php 
            }
        ?>
         
</html>
